﻿<%@ Page Language="C#" MasterPageFile="~/Template.master" AutoEventWireup="true" CodeFile="Invoice.aspx.cs" Inherits="InvoicePage" Title="Ghasam | InvoiceList" %>

<%@ Register
    Assembly="AjaxControlToolkit"
    Namespace="AjaxControlToolkit"
    TagPrefix="ajaxToolkit" %>
    
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ScriptManager ID="smInvoice" runat="server" />
    
    <div class="title">
        لیست صورتحساب های فروش
    </div>
    <div style="clear:both; padding:0 0 30px 0; height:90px;">
        موارد مورد جستجو
        <br />
        <br />
        <div>
            از تاریخ
        <asp:TextBox ID="txtStartDate" style="direction:ltr; text-align:left" Width="100" runat="server" />
        <asp:RegularExpressionValidator ID="revStartDate" runat="server" ControlToValidate="txtStartDate" Display="Dynamic" ErrorMessage="تاریخ صحیح نمی باشد" ValidationExpression="(13)?[1-9][0-9]/(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])">*</asp:RegularExpressionValidator>
        <ajaxToolkit:MaskedEditExtender ID="meeStartDate" runat="server"
                            TargetControlID="txtStartDate" 
                            Mask="9999/99/99"
                            MessageValidatorTip="true"
                            CultureName="fa-IR"
                            OnFocusCssClass="MaskedEditFocus"
                            OnInvalidCssClass="MaskedEditError"
                            MaskType="None"
                            AcceptNegative="Left" />
        تا تاریخ
        <asp:TextBox ID="txtEndDate" style="direction:ltr; text-align:left" Width="100" runat="server" />
        <asp:RegularExpressionValidator ID="revEndDate" runat="server" ControlToValidate="txtEndDate" Display="Dynamic" ErrorMessage="تاریخ صحیح نمی باشد" ValidationExpression="(13)?[1-9][0-9]/(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])">*</asp:RegularExpressionValidator>
        <ajaxToolkit:MaskedEditExtender ID="meeEndDate" runat="server"
                            TargetControlID="txtEndDate" 
                            Mask="9999/99/99"
                            MessageValidatorTip="true"
                            CultureName="fa-IR"
                            OnFocusCssClass="MaskedEditFocus"
                            OnInvalidCssClass="MaskedEditError"
                            MaskType="None"
                            AcceptNegative="Left" />
        <br />
        <br />
            <asp:SqlDataSource ID="sdsGoods" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServerInstance %>"
                SelectCommand="SELECT * FROM [Goods]"></asp:SqlDataSource>
            کالا
            <asp:DropDownList ID="ddlGoods" runat="server" AppendDataBoundItems="True" DataSourceID="sdsGoods" DataTextField="Name" DataValueField="ID" >
                <asp:ListItem Value="-1">---</asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="btnSearch" Text="جستجو" runat="server" OnClick="btnSearch_Click" />
        </div>
        <div id="divHiddenCustomers" style="float:right; width:400px; padding-top:15px;" runat="server">
            <asp:RadioButton ID="rbFormalCustomers" GroupName="rbCustomers" OnCheckedChanged="CustomerTypeCheckedChanged" AutoPostBack="true" Text="گروه الف" runat="server" />
            &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:RadioButton ID="rbHiddenCustomers" GroupName="rbCustomers" OnCheckedChanged="CustomerTypeCheckedChanged" AutoPostBack="true" Text="گروه ب" runat="server" />
            &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:RadioButton ID="rbAll" GroupName="rbCustomers" Checked="true" AutoPostBack="true" Text="همه مشتریان" runat="server" OnCheckedChanged="CustomerTypeCheckedChanged" />
        </div>
    </div>
    <div>
        * به صورت پیش فرض فاکتور های هفت روز گذشته نمایش داده می شود
    </div>
    <hr />
    <div>
        <mani:PagingGridView ID="gvInvoice" runat="server" VirtualItemCount="-1" 
            AllowPaging="true" PageSize="15" 
                             AutoGenerateColumns="False" DataKeyNames="Id" 
                             OnSelectedIndexChanged="gvInvoice_SelectedIndexChanged" 
            OnPageIndexChanging="gvInvoice_PageIndexChanging" onsorting="gvInvoice_Sorting">
            <Columns>
                <asp:BoundField DataField="Id" HeaderText="کد داخلی" ReadOnly="True" SortExpression = "Id"/>
                <asp:BoundField DataField="Serial" HeaderText="شماره سریال" SortExpression = "Serial"/>
                <asp:BoundField DataField="CustomerName" HeaderText="نام مشتری" ReadOnly="True" SortExpression = "customer.CustomerName"/>
                <asp:CheckBoxField DataField="IsFormal" HeaderText="گروه الف" />
                <asp:BoundField DataField="GoodsName" HeaderText="کالا" SortExpression = "goods.Name"/>
                <asp:BoundField DataField="NetWeight" HeaderText="وزن خالص" />
                <asp:BoundField DataField="VehicleNo" HeaderText="شماره کامیون"  SortExpression = "VehicleNo"/>
                
                <asp:TemplateField HeaderText="قیمت واحد" SortExpression = "UnitCost">
                    <ItemTemplate>
                        <%#  Mani.Common.UIHelper.FormatString(Eval("UnitCost"))%>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="مبلغ کل" SortExpression = "TotalPrice">
                    <ItemTemplate>
                        <%# Mani.Common.UIHelper.FormatString(Eval("TotalPrice"))%>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="آخرین ویرایش" SortExpression = "LastUpdate">
                    <ItemTemplate>
                        <%# Mani.Common.MyPersianDate.DateTimeToPersian(Eval("LastUpdate"))%>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="PrintInvoice" runat="server" CausesValidation="False" CommandName="Select">
                                <img src="img/print.jpg" alt="" style="border:0;" />
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="DeleteInvoice" runat="server" CausesValidation="False" CommandName="Delete">
                                <img src="App_Themes/<%=Page.Theme %>/images/delete.gif" alt="" style="border:0;" />
                        </asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </mani:PagingGridView>
        
        <%-- 
        <asp:SqlDataSource ID="sdsInvoice" runat="server" 
        ConnectionString="$ ConnectionStrings:LocalSqlServerInstance " 
        SelectCommand="SELECT * FROM vwInvoice WHERE [IsFormal] <> @IsFormal AND (GoodsID = @GoodsID OR @GoodsID = -1) AND LastUpdate >= @StartDate AND LastUpdate <= @EndDate Order by ID DESC" OnSelecting="sdsInvoice_Selecting"
        DeleteCommand="Delete From Invoice WHERE ID = @ID">
            <SelectParameters>
                <asp:Parameter Name="IsFormal" Type="Int32" />
                <asp:Parameter Name="StartDate" Type="DateTime" />
                <asp:Parameter Name="EndDate" Type="DateTime" />
                <asp:ControlParameter ControlID="ddlGoods" Name="GoodsID" PropertyName="SelectedValue" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
        </asp:SqlDataSource>
        --%>
    </div>
</asp:Content>

